package com.example.delll.kugou.Welcome_activity;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.example.delll.kugou.R;
import com.example.delll.kugou.activity.MainActivity;
import com.example.delll.kugou.fragment.SYFragment;

public class Welcome_item extends AppCompatActivity implements View.OnClickListener {
    private TextView tv_show;
    private static final String TAG="Welcome_item";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome_item);
        initView();
        h.sendMessage(h.obtainMessage(1, 3, 0));    }



    private Handler h = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message message) {
            switch (message.what) {
                case 1:
                    if (message.arg1 < 0) {
                        h.sendEmptyMessage(2);
                    } else {
                        Log.d(TAG, "handleMessage: 555555555555555");
                        String s = message.arg1 + "s 后跳过";
                        tv_show.setText(s);
                        Log.d(TAG, "handleMessage: 666666666666"+s);
                        Message obtain = Message.obtain();
                        obtain.what = 1;
                        obtain.arg1 = message.arg1 - 1;
                        Log.d(TAG, "handleMessage: 77777777777777"+obtain.arg1);
                        h.sendMessageDelayed(obtain, 1500);

                    }
                    break;
                case 2:
                    go2Main();
                    break;

            }

            return false;
        }
    });


    public void go2Main() {
        startActivity(new Intent(this, MainActivity.class));
        finish();
    }

    @Override
    public void onBackPressed() {
//        super.onBackPressed();
    }

    private void initView() {
        tv_show = findViewById(R.id.tv_show);
        tv_show.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_show:
                h.removeMessages(1);
                h.removeMessages(2);
                go2Main();
                break;

        }
    }
}
